<template>
  <l-layout class="l-tab-page learun-file-form-page">
    <template v-if="selectId">
      <div class="l-rblock" style="background: #fff;"
        v-if="['txt', 'csv', 'html', 'pdf'].includes(lr_getFileEex(selectFile.name))">
        <iframe :src="previewUrl" class="l-iframe" ref="iframe" frameborder="0"></iframe>
      </div>
      <div class="l-rblock learun-img-preview"
        v-else-if="['jpg', 'JPG','gif', 'png', 'PNG', 'bmp', 'jpeg', 'svg'].includes(lr_getFileEex(selectFile.name))">
        <img class="learun-img-preview-img" :src="previewUrl" alt="">
      </div>
      <div class="l-rblock learun-not-preview" v-else>
        <i class="icon" :class="lr_getFileIcon(selectFile.name).icon"
          :style="{color: lr_getFileIcon(selectFile.name).color}"></i>
        <p class="text">很抱歉，无法在浏览器预览 {{lr_getFileEex(selectFile.name)}} 文件,请下载后查看</p>
        <el-button @click="downFile(selectFile)" class="btn" type="primary">{{$t('下载文件')}}</el-button>
      </div>
    </template>
  </l-layout>
</template>
<script>

export default {
  props: {
    file: {
      type: Object,
      default: () => { },
    },
    level: String,
  },
  data() {
    return {
      configActiveName: "tab01",
      historys: [],
    };
  },
  watch: {
    fileId: {
      handler() {
        this.configActiveName = "tab01"
      },
      immediate: true,
    },
  },
  computed: {
    fileId() {
      if (this.file) {
        return this.file.id;
      } else {
        return "";
      }
    },
    selectId() {
      return this.file.id || ''
    },
    selectFile() {
      return this.file
    },
    previewUrl() {
      return `${this.apiUrl}system/annexesfile/preview/${this.selectFile.id}?token=${this.token}`
    },
  },
  methods: {
    handleCommand(command) {
      if (command.type == "down") {
        this.$downFile(
          `${this.apiUrl}system/annexesfile/${command.item.id}?token=${this.token}`
        );
      }
    },
    downFile(item) {
      this.$downFile(
        `${this.apiUrl}system/annexesfile/${item.id}?token=${this.token}`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.learun-list-item-icon {
  height: 56px;
}
.ver {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 28px;
  line-height: 24px;
  border-radius: 100%;
  background: #c5cedb;
  border: 2px solid #fff;
  color: #fff;
  font-size: 12px;
  text-align: center;
}
.learun-list-item-wraper {
  min-height: 56px;
}
.time {
  .learun-list-item-icon:after {
    content: "";
    position: absolute;
    left: 50%;
    top: 28px;
    bottom: 0;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
    width: 2px;
    opacity: 0.04;
    background: #000;
  }
  .learun-list-item-icon:before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 28px;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
    width: 2px;
    opacity: 0.04;
    background: #000;
  }

  .learun-list-item:first-child {
    .learun-list-item-icon:before {
      display: none;
    }
  }
  .learun-list-item:last-child {
    .learun-list-item-icon:after {
      display: none;
    }
  }
}

.learun-list-item.active {
  background-color: #4285f414;
  .ver {
    background: #4285f4;
  }
  .learun-list-item-title {
    color: #4285f4;
  }
}

.learun-img-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  &-img {
    opacity: 1;
    transition: all 0.2s ease-in-out;
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 3px 0 rgb(0 0 0 / 5%), 0 0 1px 0 rgb(0 0 0 / 5%);
    background: url()
      repeat;
  }
}
.learun-not-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  .icon {
    font-size: 64px;
    margin-bottom: 16px;
  }
  .text {
    color: rgba(0, 0, 0, 0.85);
    font-size: 16px;
    margin-bottom: 16px;
  }
}
</style>
<style lang="scss">
.learun-file-form-page {
  .el-upload-dragger {
    width: 264px;
    height: 80px;

    .el-icon-upload {
      font-size: 48px;
      line-height: 48px;
      margin: 0;
    }
  }

  .el-dropdown-link {
    height: 24px;
    width: 24px;
    line-height: 24px;
    text-align: center;
  }
}
</style>